package view.components
{
	import flash.events.TimerEvent;
	
	import utils.EnterFrameTimer;
	
	public class CountTimerText
	{
		private var timer:EnterFrameTimer;
		private var totalS:uint;
		
		public function CountTimerText()
		{
			initTimer();	
		}
		
		private function initTimer():void
		{
			timer = new EnterFrameTimer(1000);
			timer.addEventListener(TimerEvent.TIMER,onTimer);
		}
		
		private function onTimer(event:TimerEvent):void
		{
			totalS--;
			if (totalS <= 0)
			{
				timer.stop();
			}
		}
		
		public function init(total:uint):void
		{
			totalS = total;
		}
		
		public function start():void
		{
			timer.start();
		}
		
		public function stop():void
		{
			timer.reset();
		}
		
		public function get text() : String
		{
			var hour:int = totalS / 3600;
			var minute:int = (totalS % 3600) / 60;
			var second:int = totalS % 60;
			
			return hour + "小时" + minute + "分" + second + "秒";
		}
		
		public function destroy():void
		{
			timer.removeEventListener(TimerEvent.TIMER,onTimer);
			timer = null;
		}
	}
}